using System;

namespace Noix.IMAP
{
    public class IMAPMessage
    {

        public IMAPMessage(string uid)
        {
            _uid = uid;
        }
        
        private string _uid = null;
        private string _from = null;
        private string _to = null;
        private string _subject = "";
        private DateTime _date = DateTime.Now;
        private string _text = null;
        private bool _seen = false;
        private bool _answered = false;
        private bool _flagged = false;
        private bool _deleted = false;
        private bool _draft = false;
        private bool _recent = false;

        public string Uid
        {
            get { return _uid; }
            set { _uid = value; }
        }

        public string From
        {
            get { return _from; }
            set { _from = value; }
        }

        public string To
        {
            get { return _to; }
            set { _to = value; }
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        public DateTime Date
        {
            get { return _date; }
            set { _date = value; }
        }

        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }

        public void SetFlags(string str)
        {
            if (str.IndexOf("\\Seen") > -1) _seen = true;
            if (str.IndexOf("\\Answered") > -1) _answered = true;
            if (str.IndexOf("\\Flagged") > -1) _flagged = true;
            if (str.IndexOf("\\Deleted") > -1) _deleted = true;
            if (str.IndexOf("\\Draft") > -1) _draft = true;
            if (str.IndexOf("\\Recent") > -1) _recent = true;
        }

        public string GetFlags()
        {
            string result = null;
            if (_seen == true) result += "\\Seen ";
            if (_answered == true) result += "\\Answered ";
            if (_flagged == true) result += "\\Flagged ";
            if (_deleted == true) result += "\\Deleted ";
            if (_draft == true) result += "\\Draft ";
            if (_recent == true) result += "\\Recent ";
            return result.Trim();
        }
    }
}
